home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / Peon / PeonSDK-Win32-1.0.0.exe / {app} / PeonMain / include / IApplication.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-11-21  |  3.8 KB  |  134 lines

  1.  
  2. #ifndef __IAPPLICATION_H_
  3. #define __IAPPLICATION_H_
  4. /*
  5. Peon - Win32 Games Programming Library
  6. Copyright (C) 2002-2005 Erik Yuzwa
  7.  
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public
  10. License as published by the Free Software Foundation; either
  11. version 2 of the License, or (at your option) any later version.
  12.  
  13. This library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. Library General Public License for more details.
  17.  
  18. You should have received a copy of the GNU Library General Public
  19. License along with this library; if not, write to the Free
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.  
  22. Erik Yuzwa
  23. peon AT wazooinc DOT com
  24. */
  25.  
  26. #include "IApplicationState.h"
  27.  
  28. namespace peon
  29. {
  30.     /**
  31.     * This object is responsible for containing any "application global" 
  32.     * structures or handles. You should stick state-specific objects
  33.     * into an IApplicationState instance, but any object that needs to be
  34.     * referenced by all the internal states should be thrown into here
  35.     */
  36.     class PEONMAIN_API IApplication 
  37.     {
  38.     protected:
  39.         /** a hashmap container of our IApplicationState pointers */
  40.         std::map<int, IApplicationState*> m_oStates;
  41.  
  42.         /** a handle to our current IApplicationState instance */
  43.         IApplicationState*    m_pCurrentState;
  44.  
  45.     public:
  46.         /**
  47.         * Constructor
  48.         */
  49.         IApplication();
  50.  
  51.         /**
  52.         * Destructor
  53.         */
  54.         virtual ~IApplication();
  55.  
  56.         /**
  57.         * This method is called when loading the game world. In here
  58.         * we should be loading all of the internal IApplicationState instances
  59.         * along with any "global level" objects
  60.         * @return bool - true if successfull
  61.         */
  62.         virtual bool onLoadWorld() = 0;
  63.  
  64.         /**
  65.         * This method is called when unloading the game world. Basically
  66.         * any object that we created at a global level should be cleaned
  67.         * up here.
  68.         * Note that the IApplicationState instances are cleanup automatically,
  69.         * so you do not need to worry about them.
  70.         */
  71.         virtual void onUnloadWorld() = 0;
  72.  
  73.         /**
  74.         * This method is called when it's time to pass any rendering command
  75.         * to the engine
  76.         */
  77.         virtual void onRenderWorld(){}
  78.  
  79.         /**
  80.         * This method is called when it's time to update the objects in
  81.         * the game world. 
  82.         * @param fElapsedTime - the time differential used for object position
  83.         * calculations
  84.         */
  85.         virtual void onUpdateWorld( float fElapsedTime ) = 0;
  86.  
  87.         /**
  88.         * This method is responsible for loading the 
  89.         * given IApplicationState along with registering it 
  90.         * into our hashtable
  91.         * @param key - key id for the local hashmap
  92.         * @param pState - a new @IApplicationState
  93.         * @return bool - TRUE if everything initialized okay
  94.         */
  95.         bool loadState( int key, IApplicationState* pState );
  96.  
  97.         /**
  98.         * This is an internal method to clean up all the states
  99.         */
  100.         void unloadStates();
  101.     
  102.         /**
  103.         * This just returns the current IApplicationState that the engine
  104.         * is working with.
  105.         * @return IApplicationState*  - a handle to the current IApplicationState
  106.         */
  107.         IApplicationState* getCurrentState(){ return m_pCurrentState; }
  108.         
  109.         /**
  110.         * Set the current state to the one specified by the key identifier
  111.         * param key - key to set current state to
  112.         */
  113.         void setCurrentState(int key);
  114.  
  115.         /**
  116.         * This method is overrideable to provide quick keyboard access to the
  117.         * current state
  118.         * @param pEvent - a generated SDL_KeyboardEvent handle
  119.         */
  120.         virtual void onKeyEvent( SDL_KeyboardEvent* pEvent ){}
  121.  
  122.         /**
  123.         * This method is overrideable to provide quick mouse access to the 
  124.         * current state
  125.         * @param pEvent - a generated SDL_Event message
  126.         */
  127.         virtual void onMouseEvent( SDL_Event* pEvent ){}
  128.  
  129.     };
  130. }
  131.  
  132. #endif
  133.  
  134.